package top.canyue.eca_manager.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import top.canyue.eca_manager.bean.Todo;

import java.sql.Date;
import java.util.List;

@Mapper
public interface TodoMapper {
    @Insert(value = "INSERT INTO todo(id, userId, event, endDate, createTime) VALUES (MD5(UUID()),#{userId},#{event},#{endDate},NOW())")
    Integer addEvent(String userId, String event, Date endDate);

    @Select(value = "SELECT * FROM todo WHERE id = #{id}")
    Todo findById(String id);

    //DATE不影响索引
    @Select(value = "SELECT * FROM todo WHERE userId = #{userId} AND isDelete = 0 AND endDate >= DATE(NOW())")
    List<Todo> findByUserId(String userId);

    @Update(value = "UPDATE todo SET isDelete = 1, updateTime = NOW() WHERE id = #{id}")
    Integer deleteById(String id);

}
